package com.sxz.sbs.module.home.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.entity.UploadAppBean;
import com.sxz.sbs.module.home.bean.HomeBean;
import com.sxz.sbs.module.home.bean.WeatherBean;
import com.sxz.sbs.module.home.view.HomeView;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;

/**
 * 首页 presenter
 */

public class HomePresenter extends RxPresenter<HomeView>{
    /**
     * 获取首页数据
     * @param map
     */
    public void getHomeData (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getHomeData(map)
                .compose(RxUtil.<HomeBean>handleResult())
                .subscribeWith(new RxSubscriber<HomeBean>(mView,true){
                    @Override
                    public void onNext(HomeBean token) {
                        mView.onGetHomeDataSuccess(token);
                    }
                })
        );
    }
    /**
     * 获取天气
     * @param map
     */
    public void getWeatherData (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getWeather(map)
                .compose(RxUtil.<WeatherBean>handleResult())
                .subscribeWith(new RxSubscriber<WeatherBean>(mView){
                    @Override
                    public void onNext(WeatherBean bean) {
                        mView.onGetWeatherDataSuccess(bean);
                    }
                })
        );
    }
    /**
     * 获取版本更新
     * @param map
     */
    public void getVersion (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().uploadApp(map)
                .compose(RxUtil.<UploadAppBean>handleResult())
                .subscribeWith(new RxSubscriber<UploadAppBean>(mView){
                    @Override
                    public void onNext(UploadAppBean bean) {
                        mView.onGetVersionSuccess(bean);
                    }
                })
        );
    }

}
